<?
/**
 * UserEdit.php
 *
 * This page is for users to edit their account information
 * such as their password, email address, etc. Their
 * usernames can not be edited. When changing their
 * password, they must first confirm their current password.
 *
 */
include("include/session.php");
?>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="Description" content="Information about the Symposium on Racing & Gaming, presented by the University of Arizona Race Track Industry Program. Includes sponsors, exhibitors, panel sessions, award winners, photos, transcripts and presentations" />
    <meta name="Keywords" content="horseracing, horse racing, race track education, race horse, racehorse, greyhound tracks, horsetrack, thoroughbred racing, quarterhorse racing, horse breeding, pari-mutuel, parimutuel, equine education, greyhound racing, dog racing, harness racing, horse training, symposium on racing, multi-breed, racetrack industry, turf racing, rtip, gaming, betting, racetrack betting, University of Louisville, racetrack education, racetrack school, race track school, horseracing school, horseracing college, horse racing college, racetrack college, race track college, equine school, equine college, equine program, symposium on gaming" />
 
   <title>Edit Your Information</title>
    <link href="css/rtip.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="phone.js"></script>
</head>

<body>

<div id="wrap">
    <div id="topbar">
	<a href="http://www.arizona.edu/" target="_blank"></a>
    </div>
    <div id="top">
        <div id="head_image"> </div>
    </div>

    <div id="page_head">
        <h2 id="left_head"> </h2>
        <h2 id="right_head"> </h2>

    </div>


<?
/**
 * User has submitted form without errors and user's
 * account has been edited successfully.
 */
if(isset($_SESSION['useredit'])){
   unset($_SESSION['useredit']);
   $req_user_info = $database->getUserInfo($session->username);
   echo "<h1 ALIGN=\"CENTER\">User Account Edit Success!</h1>";
   echo "<p ALIGN=\"CENTER\"><b>".$req_user_info['fname']." ".$req_user_info['lname']."</b>, your account has been successfully updated.</br>";
   ?> <FORM  ALIGN="CENTER" METHOD="LINK" ACTION="main.php">
   <INPUT TYPE="submit" VALUE="Home">
   </FORM><? 
}
else{
?>

<?
/**
 * If user is not logged in, then do not display anything.
 * If user is logged in, then display the form to edit
 * account information, with the current email address
 * already in the field.
 */
if($session->logged_in){
    $req_user_info = $database->getUserInfo($session->username);
?>

<h1 ALIGN="CENTER">User Account Edit : <? echo $req_user_info['fname']." ".$req_user_info['lname']; ?></h1>
<?
if($form->num_errors > 0){
   echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST">
    <table id="users" align="left" border="0" cellspacing="0" cellpadding="3">
        <tr>
            <td id="users">First Name:</td>
            <td id="users" ><input type="text" name="fname" maxlength="50" value="<?
                    if($form->value("fname") == "")
                        { echo trim($session->userinfo['fname']); }
                    else{ echo $form->value("fname"); }
                ?>"></td>
            <td><? echo $form->error("fname"); ?></td>
        </tr>
        <tr>
            <td>Last Name:</td>
            <td><input type="text" name="lname" maxlength="50" value="<?
                    if($form->value("lname") == "")
                        { echo $session->userinfo['lname']; }
                    else{ echo $form->value("lname"); }
                ?>"></td>
            <td><? echo $form->error("lname"); ?></td>
        </tr>
        <tr>
            <td>Organization:</td>
            <td><input type="text" name="organization" maxlength="50" value="<?
                    if($form->value("organization") == "")
                        { echo $session->userinfo['organization']; }
                    else{ echo $form->value("organization"); }
                ?>"></td>
            <td><? echo $form->error("organization"); ?></td>
        </tr>
        <tr>
            <td>Website:</td>
            <td><input type="text" name="website" maxlength="50" value="<?
                    if($form->value("website") == "")
                        { echo $session->userinfo['website']; }
                    else{ echo $form->value("website"); }
                ?>"></td>
            <td><? echo $form->error("website"); ?></td>
        </tr>
        <tr>
            <td>Phone Number:</td>
            <td><input type="text" name="phone" maxlength="50" value="<?
                    if($form->value("phone") == "")
                        { echo $session->userinfo['phone']; }
                    else{ echo $form->value("phone"); }
                ?>" onkeydown="backspacerDOWN(this,event);" onkeyup="backspacerUP(this,event);" /></td>
            <td><? echo $form->error("phone"); ?></td>
        </tr>
        <tr>
            <td>Address:</td>
            <td><input type="text" name="address" maxlength="50" value="<?
                    if($form->value("address") == "")
                        { echo $session->userinfo['address']; }
                    else{ echo $form->value("address"); }
                ?>"></td>
            <td><? echo $form->error("address"); ?></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type="text" name="email" maxlength="50" value="<?
                    if($form->value("email") == "")
                        { echo $session->userinfo['email']; }
                    else{ echo $form->value("email"); }
                ?>"></td>
            <td><? echo $form->error("email"); ?></td>
        </tr>

        <tr>
            <td colspan="2" align="right">
                <input type="hidden" name="subedit" value="1">
                <input type="submit" value="Save Changes">
            </td>
        </tr>
        <tr>
            <td colspan="2" align="left"></td>
        </tr>
    </table>
</form>

<?
    }
}
?>
</div>
</body>
</html>
